export interface Contact {
  firstName: string;
  lastName: string;
}

export const contactsData: Contact[] = [
  {
    firstName: 'Illana',
    lastName: 'Torres',
  },
  {
    firstName: 'Rogan',
    lastName: 'Mcleod',
  },
  {
    firstName: 'Joy',
    lastName: 'Blackwell',
  },
  {
    firstName: 'Brent',
    lastName: 'Frazier',
  },
  {
    firstName: 'Cathleen',
    lastName: 'Holloway',
  },
  {
    firstName: 'Ashton',
    lastName: 'Bean',
  },
  {
    firstName: 'Brianna',
    lastName: 'Knox',
  },
  {
    firstName: 'Shafira',
    lastName: 'Hester',
  },
  {
    firstName: 'Eric',
    lastName: 'Blanchard',
  },
  {
    firstName: 'Brenda',
    lastName: 'Charles',
  },
  {
    firstName: 'Malachi',
    lastName: 'Blankenship',
  },
  {
    firstName: 'Jillian',
    lastName: 'Burt',
  },
  {
    firstName: 'Elton',
    lastName: 'Harris',
  },
  {
    firstName: 'Brody',
    lastName: 'Lyons',
  },
  {
    firstName: 'Quin',
    lastName: 'Becker',
  },
  {
    firstName: 'Latifah',
    lastName: 'Blair',
  },
  {
    firstName: 'Haviva',
    lastName: 'Morgan',
  },
  {
    firstName: 'Laura',
    lastName: 'Carey',
  },
  {
    firstName: 'Alyssa',
    lastName: 'Ballard',
  },
  {
    firstName: 'Colton',
    lastName: 'Mitchell',
  },
  {
    firstName: 'Walker',
    lastName: 'Robinson',
  },
  {
    firstName: 'Vanna',
    lastName: 'Gilbert',
  },
  {
    firstName: 'Xantha',
    lastName: 'Buckley',
  },
  {
    firstName: 'Edan',
    lastName: 'Barnes',
  },
  {
    firstName: 'Ralph',
    lastName: 'Barrera',
  },
  {
    firstName: 'Catherine',
    lastName: 'Bishop',
  },
  {
    firstName: 'Ishmael',
    lastName: 'Burris',
  },
  {
    firstName: 'Zoe',
    lastName: 'Joyner',
  },
  {
    firstName: 'Graiden',
    lastName: 'Fleming',
  },
  {
    firstName: 'Emerson',
    lastName: 'Johns',
  },
  {
    firstName: 'Imani',
    lastName: 'Willis',
  },
  {
    firstName: 'Noah',
    lastName: 'Gardner',
  },
  {
    firstName: 'Leah',
    lastName: 'Massey',
  },
  {
    firstName: 'Justin',
    lastName: 'Yang',
  },
  {
    firstName: 'Martina',
    lastName: 'Humphrey',
  },
  {
    firstName: 'Bruce',
    lastName: 'Stuart',
  },
  {
    firstName: 'Emery',
    lastName: 'Mccarty',
  },
  {
    firstName: 'Knox',
    lastName: 'Graves',
  },
  {
    firstName: 'Michael',
    lastName: 'Green',
  },
  {
    firstName: 'Hedwig',
    lastName: 'Moon',
  },
  {
    firstName: 'Jerry',
    lastName: 'Estes',
  },
  {
    firstName: 'Carter',
    lastName: 'Bright',
  },
  {
    firstName: 'Molly',
    lastName: 'Watts',
  },
  {
    firstName: 'Wendy',
    lastName: 'Acevedo',
  },
  {
    firstName: 'Xavier',
    lastName: 'Stuart',
  },
  {
    firstName: 'Neville',
    lastName: 'Grimes',
  },
  {
    firstName: 'Gay',
    lastName: 'Flowers',
  },
  {
    firstName: 'Azalia',
    lastName: 'Barber',
  },
  {
    firstName: 'Phyllis',
    lastName: 'Castaneda',
  },
  {
    firstName: 'Caryn',
    lastName: 'Chase',
  },
  {
    firstName: 'Gannon',
    lastName: 'Mccray',
  },
  {
    firstName: 'Halla',
    lastName: 'Ortiz',
  },
  {
    firstName: 'Carl',
    lastName: 'Cochran',
  },
  {
    firstName: 'Naida',
    lastName: 'Cooke',
  },
  {
    firstName: 'Dean',
    lastName: 'Craig',
  },
  {
    firstName: 'Kylan',
    lastName: 'Estrada',
  },
  {
    firstName: 'Daphne',
    lastName: 'Young',
  },
  {
    firstName: 'Abraham',
    lastName: 'Sears',
  },
  {
    firstName: 'Clementine',
    lastName: 'Herman',
  },
  {
    firstName: 'Nasim',
    lastName: 'Hays',
  },
  {
    firstName: 'Deanna',
    lastName: 'Sanford',
  },
  {
    firstName: 'Chadwick',
    lastName: 'Crosby',
  },
  {
    firstName: 'Renee',
    lastName: 'Burks',
  },
  {
    firstName: 'Keaton',
    lastName: 'Lancaster',
  },
  {
    firstName: 'Macaulay',
    lastName: 'Barker',
  },
  {
    firstName: 'Lana',
    lastName: 'Suarez',
  },
  {
    firstName: 'Brent',
    lastName: 'Valenzuela',
  },
  {
    firstName: 'Brittany',
    lastName: 'Wade',
  },
  {
    firstName: 'Quamar',
    lastName: 'Bond',
  },
  {
    firstName: 'Uma',
    lastName: 'Padilla',
  },
  {
    firstName: 'Tasha',
    lastName: 'Nixon',
  },
  {
    firstName: 'Wayne',
    lastName: 'Dennis',
  },
  {
    firstName: 'Nathaniel',
    lastName: 'Kelley',
  },
  {
    firstName: 'Dale',
    lastName: 'Johnston',
  },
  {
    firstName: 'Linda',
    lastName: 'Puckett',
  },
  {
    firstName: 'Emery',
    lastName: 'Diaz',
  },
  {
    firstName: 'Gillian',
    lastName: 'Bryan',
  },
  {
    firstName: 'Rooney',
    lastName: 'Medina',
  },
  {
    firstName: 'Nita',
    lastName: 'May',
  },
  {
    firstName: 'Haviva',
    lastName: 'Glass',
  },
  {
    firstName: 'Randall',
    lastName: 'Gaines',
  },
  {
    firstName: 'Trevor',
    lastName: 'Witt',
  },
  {
    firstName: 'Ariel',
    lastName: 'Barnes',
  },
  {
    firstName: 'Nichole',
    lastName: 'Stanley',
  },
  {
    firstName: 'Quinn',
    lastName: 'Webb',
  },
  {
    firstName: 'Magee',
    lastName: 'Blackwell',
  },
  {
    firstName: 'Celeste',
    lastName: 'Gibson',
  },
  {
    firstName: 'Noelle',
    lastName: 'Grimes',
  },
  {
    firstName: 'Basil',
    lastName: 'Parsons',
  },
  {
    firstName: 'Yvette',
    lastName: 'French',
  },
  {
    firstName: 'Quemby',
    lastName: 'Silva',
  },
  {
    firstName: 'Alika',
    lastName: 'Shaffer',
  },
  {
    firstName: 'Peter',
    lastName: 'Adkins',
  },
  {
    firstName: 'Alden',
    lastName: 'Watson',
  },
  {
    firstName: 'Neil',
    lastName: 'ONeill',
  },
  {
    firstName: 'Marvin',
    lastName: 'Allen',
  },
  {
    firstName: 'Ivy',
    lastName: 'Dickerson',
  },
  {
    firstName: 'Brody',
    lastName: 'Vega',
  },
  {
    firstName: 'Hunter',
    lastName: 'Mitchell',
  },
  {
    firstName: 'Brenda',
    lastName: 'Hurley',
  },
];

const contacts = contactsData.reduce((contactsMap, contact) => {
  const lastNameInitial = contact.lastName[0];
  const currentLetterContacts = contactsMap.get(lastNameInitial) ?? [];
  contactsMap.set(lastNameInitial, [...currentLetterContacts, contact]);
  return contactsMap;
}, new Map<string, Contact[]>());

contacts.forEach((_contacts: Contact[], key: string, map: Map<string, Contact[]>) => {
  const sortedContacts = _contacts.sort((aContact, bContact) => aContact.lastName.localeCompare(bContact.lastName));
  map.set(key, sortedContacts);
});

export default contacts;
